package test;


import benchmark.Benchmark;
import data.IntegerDataSetGenerator;
import implementation.sort.ShellSorter;

import java.util.ArrayList;
import java.util.Comparator;

public class ShellReport {

    private static Benchmark benchmark;

    public static void main(String[] args) {

        benchmark = new Benchmark();
        ShellSorter shellSorter = new ShellSorter();
        shellSorter.addSorterListener(benchmark);
        IntegerDataSetGenerator dataSetGenerator = new IntegerDataSetGenerator();
        Comparator comparator = dataSetGenerator.getComparator();

        int[] cant = {100, 1000, 10000, 50000};
        for (int i = 0; i < cant.length; i++) {
            int n = cant[i];
            System.out.println("\n\nN = " + n);
            ArrayList<Integer> list = (ArrayList) dataSetGenerator.createRandom(n);
            ArrayList<Integer> copyList = (ArrayList) list.clone();


            System.out.println("\tSequence 1: ");
            ArrayList<Integer> sequence1 = generateSequence1();
            printList(sequence1);
            printReport(shellSorter, sequence1, comparator, list);

            System.out.println("\n\tSequence 2: ");
            ArrayList<Integer> sequence2 = generateSequence2();
            printList(sequence2);
            printReport(shellSorter, sequence2, comparator, copyList);
        }
    }

    private static void printReport(ShellSorter shellSorter, ArrayList<Integer> sequence, Comparator tComparator, ArrayList list) {
        shellSorter.setSequence(sequence);
        long t0 = System.currentTimeMillis();

        shellSorter.sort(tComparator, list);
        long tf = System.currentTimeMillis();

        System.out.println("\t\tTime: " + (tf - t0));
        System.out.println("\t \tComparisons: " + benchmark.getComparisons());
    }

    private static void printList(ArrayList<Integer> list) {
        System.out.print("{ ");
        for (int i : list) {
            System.out.print(i + ", ");
        }
        System.out.println("}");
    }

    private static ArrayList<Integer> generateSequence1() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(8);
        list.add(23);
        list.add(77);
        list.add(281);
        list.add(1073);
        list.add(4193);
        list.add(16577);
        return list;
    }

    private static ArrayList<Integer> generateSequence2() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(4);
        list.add(13);
        list.add(121);
        list.add(364);
        list.add(1093);
        list.add(3280);
        list.add(9841);
        return list;
    }


}
